#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution
{
public:
    int findLHS(vector<int>& nums)
    {
		sort(nums.begin(), nums.end());
		int begin = 0;
		int res = 0;
		for (int end = 0; end < nums.size(); end++)
		{
			while (nums[end] - nums[begin] > 1)
			{
				++begin;
			}
			if (nums[end] - nums[begin] == 1)
			{
				res = max(res, end - begin + 1);
			}
		} 
		return res;
    }
};

int main()
{
	vector<int> v({ 1, 3, 2, 2, 5, 2, 3, 7 });
	Solution xz;
	int n = xz.findLHS(v);
	cout << n;
	return 0;
}